﻿using SalesSys.DAL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SalesSys.BLL
{
    public class PhoneLogBLL : BaseBLL<PhoneLog, Guid>
    {
        public void SendMsg(string msg, string token,string phone)
        {
            //消息发送待实现
            PhoneLog info = new PhoneLog();
            info.OperaMessage = msg;
            info.OperaTime = DateTime.Now;
           info.OperaUserId =token;
            info.ToPhone = phone;
            BllFactory.GetBll<PhoneLogBLL>().Create(info);
        }
        /// <summary>
        /// 通过token+手机号 获取最新的发送信息
        /// </summary>
        /// <param name="token"></param>
        /// <param name="phone"></param>
        /// <returns></returns>
        public PhoneLog GetLastTimeSendMsg(string token, string phone)
        { 
            //Guid sendUser=(Guid)token;
            return Rep.Entities.Where(p => p.ToPhone == phone && p.OperaUserId == token).OrderByDescending(p => p.OperaTime).FirstOrDefault();
        }
        /// <summary>
        /// 获取大于指定时间的所有推送消息列表
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="maxCount"></param>
        /// <returns></returns>
        public PhoneLog[] GetPushMsg(DateTime dt, int maxCount = 10)
        {
            return Rep.Entities.Where(p => p.OperaTime > dt).OrderBy(p => p.OperaTime).Take(maxCount).ToArray();
        }
    }
}
